import java.util.*;
public class pta258 {
		public static void main(String[] args) {
			Scanner in=new Scanner(System.in);
			//Can not use nextLine
			while(in.hasNext()){
				ArrayList<String> strList1=new ArrayList<String>();
				ArrayList<String> strList2=new ArrayList<String>();
				String str1,str2;
				while(in.hasNext()){
					str1=in.next();
					if(str1.endsWith("!!end!!")) break;
					strList1.add(str1);
				}
				strList1.add("end");strList1.add(0,"begin");
				System.out.println(strList1);
				//1.input str1 for index , remove
				str1=in.next();
				System.out.println(strList1.contains(str1));
				System.out.println(strList1.indexOf(str1));System.out.println(strList1.lastIndexOf(str1));System.out.println(strList1.get(0));
				strList1.remove(0); System.out.println(strList1);
				//2.input str1 for set
				str1=in.next();
				strList1.set(1, str1);
				System.out.println(strList1);
				//3.new ArrayList, remove clear 
				str1=in.next();
				for (int i=0;i<strList1.size();i++) {
					str2=strList1.get(i);
					if(str2.contains(str1)) strList2.add(str2);	
				} 
				System.out.println(strList2);
				strList1.remove(str1);System.out.println(strList1); strList1.clear();
				System.out.println(strList1+" "+strList1.size()+","+strList1.isEmpty());
			}
			in.close();
		}
}
